home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / vmail / vmail.2of3 / call.c next >
C/C++ Source or Header  |  1991-04-05  |  11KB  |  424 lines

  1. #ifndef lint
  2. static char *RCS_call_c = "$Id: call.c,v 1.5 90/09/19 13:53:33 rogers Exp $";
  3. #endif
  4.  
  5. /* --------------------
  6.     vmail -- call.c
  7.  
  8.     Routines that call MH equivalents, editor, shell.
  9.  
  10.     Copyright (C) J. Zobel, University of Melbourne, October 1987.
  11. -------------------- */
  12.  
  13. #include "defs.h"
  14. #include <signal.h>
  15.  
  16. #define WARNING    "Warning -- mail headers may be out of date"
  17.  
  18. union wait status;
  19.  
  20. /* --------------------
  21.     Fork a call to `comp'.
  22.     Terminal type must be reset before call.
  23. -------------------- */
  24. void
  25. comp()
  26. {
  27.     char    *tmp, *argv[20], str[LEN], s1[LEN], *next_token();
  28.     int        i;
  29.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  30.  
  31.     *s1 = '\0';
  32.     if(comp_args) {
  33.         (void)sprintf(str, "(give options to)   comp ");
  34.         get_string(str, s1);
  35.     }
  36.     clear();
  37.     addstatus("composing mail ...", false);
  38.     move(STATUS+1, 0);
  39.     refresh();
  40.     top_level = false;            /* used by tstp() so that right thing is done
  41.                                    when process is restarted */
  42.     if(! vfork()) {
  43.         argv[0] = COMP;
  44.         for(i=1, tmp=s1 ; *tmp != '\0' ; i++) {
  45.             argv[i] = tmp;
  46.             tmp = next_token(tmp);
  47.         }
  48.         argv[i] = 0;
  49.         no_control();
  50.         execvp(COMP, argv);
  51.         (void)printf("Warning: can't execute %s\n", COMP);
  52.         exit(0);
  53.     }
  54.     oldint = signal(SIGINT, SIG_IGN);
  55.     oldquit = signal(SIGQUIT, SIG_IGN);
  56.     (void)wait(&status);
  57.     (void)signal(SIGINT, oldint);
  58.     (void)signal(SIGQUIT, oldquit);
  59.     top_level = true;
  60.     to_control();
  61.     hold_end();                    /* wait for user to want to continue - may wish
  62.                                    to read error messages */
  63.     display_page();
  64.     addstatus(WARNING, true);    /* vmail's data structures not updated */
  65. }
  66.  
  67.  
  68. /* --------------------
  69.     Fork a call to `forw'.
  70.     Terminal type must be reset before call.
  71. -------------------- */
  72. void
  73. forw()
  74. {
  75.     char    *tmp, *argv[20], str[LEN], s1[LEN], s2[10], *next_token();
  76.     int        i;
  77.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  78.  
  79.     (void)sprintf(s2, "%d", curmail->number);
  80.     *s1 = '\0';
  81.     if(forw_args) {
  82.         (void)sprintf(str, "(give options to)   forw +%s %s ", curflr->name, s2);
  83.         get_string(str, s1);
  84.     }
  85.     clear();
  86.     addstatus("forwarding mail ...", false);
  87.     move(STATUS+1, 0);
  88.     refresh();
  89.     top_level = false;            /* used by tstp() so that right thing is done
  90.                                    when process is restarted */
  91.     if(! vfork()) {
  92.         (void)sprintf(str, "+%s", curflr->name);
  93.         argv[0] = FORW; argv[1] = str; argv[2] = s2;
  94.         for(i=3, tmp=s1 ; *tmp != '\0' ; i++) {
  95.             argv[i] = tmp;
  96.             tmp = next_token(tmp);
  97.         }
  98.         argv[i] = 0;
  99.         no_control();
  100.         execvp(FORW, argv);
  101.         (void)printf("Warning: can't execute %s\n", FORW);
  102.         exit(0);
  103.     }
  104.     oldint = signal(SIGINT, SIG_IGN);
  105.     oldquit = signal(SIGQUIT, SIG_IGN);
  106.     (void)wait(&status);
  107.     (void)signal(SIGINT, oldint);
  108.     (void)signal(SIGQUIT, oldquit);
  109.     top_level = true;
  110.     to_control();
  111.     hold_end();                    /* wait for user to want to continue - may wish
  112.                                    to read error messages */
  113.     display_page();
  114.     addstatus(WARNING, true);    /* vmail's data structures not updated */
  115. }
  116.  
  117.  
  118. /* --------------------
  119.     Fork a call to `repl'.
  120.     Terminal type must be reset before call.
  121. -------------------- */
  122. void
  123. repl()
  124. {
  125.     char    *tmp, *argv[20], str[LEN], s1[LEN], s2[10], *next_token();
  126.     int        i;
  127.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  128.  
  129.     (void)sprintf(s2, "%d", curmail->number);
  130.     *s1 = '\0';
  131.     if(repl_args) {
  132.         (void)sprintf(str, "(give options to)   repl +%s %s ", curflr->name, s2);
  133.         get_string(str, s1);
  134.     }
  135.     clear();
  136.     addstatus("answering mail ...", false);
  137.     move(STATUS+1, 0);
  138.     refresh();
  139.     top_level = false;            /* used by tstp() so that right thing is done
  140.                                    when process is restarted */
  141.     if(! vfork()) {
  142.         (void)sprintf(str, "+%s", curflr->name);
  143.         argv[0] = REPL; argv[1] = str; argv[2] = s2;
  144.         for(i=3, tmp=s1 ; *tmp != '\0' ; i++) {
  145.             argv[i] = tmp;
  146.             tmp = next_token(tmp);
  147.         }
  148.         argv[i] = 0;
  149.         no_control();
  150.         execvp(REPL, argv);
  151.         (void)printf("Warning: can't execute %s\n", REPL);
  152.         exit(0);
  153.     }
  154.     oldint = signal(SIGINT, SIG_IGN);
  155.     oldquit = signal(SIGQUIT, SIG_IGN);
  156.     (void)wait(&status);
  157.     (void)signal(SIGINT, oldint);
  158.     (void)signal(SIGQUIT, oldquit);
  159.     top_level = true;
  160.     to_control();
  161.     hold_end();                    /* wait for user to want to continue - may wish
  162.                                    to read error messages */
  163.     display_page();
  164.     addstatus(WARNING, true);    /* vmail's data structures not updated */
  165. }
  166.  
  167.  
  168. /* --------------------
  169.     Fork a call to editor.
  170.     Terminal type must be reset before call.
  171. -------------------- */
  172. void
  173. edit()
  174. {
  175.     char    str[LEN];
  176.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  177.  
  178.     clear();
  179.     mvaddstr(TITLE, 0, "editing mail ...");
  180.     move(STATUS, 0);
  181.     refresh();
  182.     top_level = false;            /* used by tstp() so that right thing is done
  183.                                    when process is restarted */
  184.     if(! vfork()) {
  185.         no_control();
  186.         (void)sprintf(str, "%s/%s/%d", mail_dir, curflr->name, curmail->number);
  187.         execlp(editor, editor, str, 0);
  188.         (void)printf("Warning: can't execute %s\n", editor);
  189.         exit(0);
  190.     }
  191.     oldint = signal(SIGINT, SIG_IGN);
  192.     oldquit = signal(SIGQUIT, SIG_IGN);
  193.     (void)wait(&status);
  194.     (void)signal(SIGINT, oldint);
  195.     (void)signal(SIGQUIT, oldquit);
  196.     top_level = true;
  197.     to_control();
  198.     hold_end();                    /* wait for user to want to continue - may wish
  199.                                    to read error messages */
  200.     display_page();
  201.     addstatus(WARNING, true);    /* vmail's data structures not updated */
  202. }
  203.  
  204.  
  205. /* --------------------
  206.     Fork a call to shell.
  207.     Terminal type must be reset before call.
  208.  
  209.     This should perhaps be modified so that only a single command can be
  210.     issued, as in vi ... but this was simpler to do.
  211. -------------------- */
  212. void
  213. call_shell()
  214. {
  215.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  216.  
  217.     clear();
  218.     mvaddstr(TITLE, 0, "calling shell ...");
  219.     move(STATUS, 0);
  220.     refresh();
  221.     top_level = false;            /* used by tstp() so that right thing is done
  222.                                    when process is restarted */
  223.     if(! vfork()) {
  224.         no_control();
  225.         fix_mh();
  226.         execlp(shell, shell, "-i", 0);
  227.         (void)printf("Warning: can't execute %s\n", shell);
  228.         exit(0);
  229.     }
  230.     oldint = signal(SIGINT, SIG_IGN);
  231.     oldquit = signal(SIGQUIT, SIG_IGN);
  232.     (void)wait(&status);
  233.     (void)signal(SIGINT, oldint);
  234.     (void)signal(SIGQUIT, oldquit);
  235.     top_level = true;
  236.     to_control();
  237.     hold_end();                    /* wait for user to want to continue - may wish
  238.                                    to read error messages */
  239.     display_page();
  240. }
  241.  
  242.  
  243. /* --------------------
  244.     Pipe current mail item into given command.
  245. -------------------- */
  246. void
  247. do_pipe()
  248. {
  249.     char    str[LEN], s1[LEN];
  250.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  251.  
  252.     *s1 = '\0';
  253.     (void)sprintf(str, "(give command to)   show +%s %d | ", curflr->name,
  254.                                                         curmail->number);
  255.     get_string(str, s1);
  256.     clear();
  257.     addstatus("piping mail ...", false);
  258.     move(STATUS+1, 0);
  259.     refresh();
  260.     (void)sprintf(str, "%s %s/%s/%d | %s", CAT, mail_dir, curflr->name,
  261.                                                         curmail->number, s1);
  262.     top_level = false;            /* used by tstp() so that right thing is done
  263.                                    when process is restarted */
  264.     no_control();
  265.     oldint = signal(SIGINT, SIG_IGN);
  266.     oldquit = signal(SIGQUIT, SIG_IGN);
  267.     (void)system(str);            /* exec needs full path of command => use system */
  268.     (void)signal(SIGINT, oldint);
  269.     (void)signal(SIGQUIT, oldquit);
  270.     top_level = true;
  271.     to_control();
  272.     hold_end();                    /* wait for user to want to continue - may wish
  273.                                    to read error messages */
  274.     display_page();
  275. }
  276.  
  277. /* --------------------
  278.     Fork a call to `burst'.
  279.     Terminal type must be reset before call.
  280. -------------------- */
  281. void
  282. burst_item()
  283. {
  284.     char    *tmp, *argv[20], str[LEN], s1[LEN], s2[10], *next_token();
  285.     int        i;
  286.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  287.  
  288.     (void)sprintf(s2, "%d", curmail->number);
  289.     *s1 = '\0';
  290.     if(burst_args) {
  291.         (void)sprintf(str, "(give options to)  burst +%s %s ", curflr->name, s2);
  292.         get_string(str, s1);
  293.     }
  294.     clear();
  295.     addstatus("bursting mail ...", false);
  296.     move(STATUS+1, 0);
  297.     refresh();
  298.     top_level = false;            /* used by tstp() so that right thing is done
  299.                                    when process is restarted */
  300.     if(! vfork()) {
  301.         (void)sprintf(str, "+%s", curflr->name);
  302.         argv[0] = BURST; argv[1] = str; argv[2] = s2;
  303.         for(i=3, tmp=s1 ; *tmp != '\0' ; i++) {
  304.             argv[i] = tmp;
  305.             tmp = next_token(tmp);
  306.         }
  307.         argv[i] = 0;
  308.         no_control();
  309.         execvp(BURST, argv);
  310.         (void)printf("Warning: can't execute %s\n", BURST);
  311.         exit(0);
  312.     }
  313.     oldint = signal(SIGINT, SIG_IGN);
  314.     oldquit = signal(SIGQUIT, SIG_IGN);
  315.     (void)wait(&status);
  316.     (void)signal(SIGINT, oldint);
  317.     (void)signal(SIGQUIT, oldquit);
  318.     top_level = true;
  319.     to_control();
  320.     hold_end();                    /* wait for user to want to continue - may wish
  321.                                    to read error messages */
  322.     clear();
  323.     move(STATUS, 0);
  324.     refresh_folder();
  325. }
  326.  
  327. /* --------------------
  328.     Fork a call to `dist'.
  329.     Terminal type must be reset before call.
  330. -------------------- */
  331. void
  332. dist_item()
  333. {
  334.     char    *tmp, *argv[20], str[LEN], s1[LEN], s2[10], *next_token();
  335.     int        i;
  336.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  337.  
  338.     (void)sprintf(s2, "%d", curmail->number);
  339.     *s1 = '\0';
  340.     if(dist_args) {
  341.         (void)sprintf(str, "(give options to)   dist +%s %s ", curflr->name, s2);
  342.         get_string(str, s1);
  343.     }
  344.     clear();
  345.     addstatus("disting mail ...", false);
  346.     move(STATUS+1, 0);
  347.     refresh();
  348.     top_level = false;            /* used by tstp() so that right thing is done
  349.                                    when process is restarted */
  350.     if(! vfork()) {
  351.         (void)sprintf(str, "+%s", curflr->name);
  352.         argv[0] = DIST; argv[1] = str; argv[2] = s2;
  353.         for(i=3, tmp=s1 ; *tmp != '\0' ; i++) {
  354.             argv[i] = tmp;
  355.             tmp = next_token(tmp);
  356.         }
  357.         argv[i] = 0;
  358.         no_control();
  359.         execvp(DIST, argv);
  360.         (void)printf("Warning: can't execute %s\n", DIST);
  361.         exit(0);
  362.     }
  363.     oldint = signal(SIGINT, SIG_IGN);
  364.     oldquit = signal(SIGQUIT, SIG_IGN);
  365.     (void)wait(&status);
  366.     (void)signal(SIGINT, oldint);
  367.     (void)signal(SIGQUIT, oldquit);
  368.     top_level = true;
  369.     to_control();
  370.     hold_end();                    /* wait for user to want to continue - may wish
  371.                                    to read error messages */
  372.     display_page();
  373.     addstatus(WARNING, true);    /* vmail's data structures not updated */
  374. }
  375.  
  376. /* --------------------
  377.     Fork a call to `sortm'.
  378.     Terminal type must be reset before call.
  379. -------------------- */
  380. void
  381. sort_folder()
  382. {
  383.     char    *tmp, *argv[20], str[LEN], s1[LEN], *next_token();
  384.     int        i;
  385.     sig_type    (*oldint)(), (*oldquit)(), (*signal())();
  386.  
  387.     *s1 = '\0';
  388.     if(sort_args) {
  389.         (void)sprintf(str, "(give options to)  sortm +%s ", curflr->name);
  390.         get_string(str, s1);
  391.     }
  392.     clear();
  393.     addstatus("sorting mail ...", false);
  394.     move(STATUS+1, 0);
  395.     refresh();
  396.     top_level = false;            /* used by tstp() so that right thing is done
  397.                                    when process is restarted */
  398.     if(! vfork()) {
  399.         (void)sprintf(str, "+%s", curflr->name);
  400.         argv[0] = SORTM; argv[1] = str;
  401.         for(i=2, tmp=s1 ; *tmp != '\0' ; i++) {
  402.             argv[i] = tmp;
  403.             tmp = next_token(tmp);
  404.         }
  405.         argv[i] = 0;
  406.         no_control();
  407.         execvp(SORTM, argv);
  408.         (void)printf("Warning: can't execute %s\n", SORTM);
  409.         exit(0);
  410.     }
  411.     oldint = signal(SIGINT, SIG_IGN);
  412.     oldquit = signal(SIGQUIT, SIG_IGN);
  413.     (void)wait(&status);
  414.     (void)signal(SIGINT, oldint);
  415.     (void)signal(SIGQUIT, oldquit);
  416.     top_level = true;
  417.     to_control();
  418.     hold_end();                    /* wait for user to want to continue - may wish
  419.                                    to read error messages */
  420.     clear();
  421.     move(STATUS, 0);
  422.     refresh_folder();
  423. }
  424.